package com.lx.pc.restful.wx;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lx.pc.domain.vo.account.AccountVo;
import com.lx.pc.domain.vo.bankcardinfo.BankcardInfoVo;
import com.lx.pc.domain.vo.evaluate.EvaluateVo;
import com.lx.pc.domain.vo.paypass.PayPassVo;
import com.lx.pc.domain.vo.user.UserVo;
import com.lx.pc.domain.vo.wcategory.WCategoryVo;
import com.lx.pc.domain.vo.worder.WOrderVo;
import com.lx.pc.domain.vo.wordercategory.WOrderCategoryVo;
import com.lx.pc.domain.vo.wpricetemplate.WPricetemplateVo;
import com.lx.pc.domain.vo.wx.WeixinVo;
import com.lx.pc.restful.BaseController;
import com.lx.pc.restful.util.AjaxResult;
import com.lx.pc.restful.util.WebUtil;
import com.lx.pc.service.account.IAccountService;
import com.lx.pc.service.accountlog.IAccountLogService;
import com.lx.pc.service.bankcardinfo.IBankcardInfoService;
import com.lx.pc.service.evaluate.IEvaluateService;
import com.lx.pc.service.paypass.IPayPassService;
import com.lx.pc.service.user.IUserService;
import com.lx.pc.service.wcategory.IWCategoryService;
import com.lx.pc.service.worder.IWOrderService;
import com.lx.pc.service.worderCategory.IWOrderCategoryService;
import com.lx.pc.service.wpricetemplate.IWPricetemplateService;
import com.lx.pc.service.wx.IWeixinService;
import com.lx.pc.utils.Constants;
import com.lx.pc.utils.RandomUtils;

/**
 * 用户
 * @author houzhong
 */
@Controller
@RequestMapping("/wx")
public class WeixinController extends BaseController{

	/**
	 * 微信获取token
	 */
	@Resource(name = "weixinService")
	private IWeixinService weixinService;
	
	/**
	 * 分类
	 */
	@Resource(name = "wCategoryService")
	private IWCategoryService wCategoryService;
	
	/**
	 * 用户
	 */
	@Resource(name = "userService")
	private IUserService userService;
	
	/**
	 * 用户订单
	 */
	@Resource(name = "wOrderService")
	private IWOrderService wOrderService;
	
	/**
	 * 用户多个分类多个重量
	 */
	@Resource(name = "wOrderCategoryService")
	private IWOrderCategoryService wOrderCategoryService;
	
	/**
	 * 参考价模版
	 */
	@Resource(name = "wPricetemplateService")
	private IWPricetemplateService wPricetemplateService;
	
	/**
	 * 个人账户
	 */
	@Resource(name = "accountService")
	private IAccountService accountService;
	
	/**
	 * 个人账户日志
	 */
	@Resource(name = "accountLogService")
	private IAccountLogService accountLogService;
	
	/**
	 * 支付密码设置
	 */
	@Resource(name = "payPassService")
	private IPayPassService payPassService;
	
	/**
	 * 银行卡
	 */
	@Resource(name = "bankcardInfoService")
	private IBankcardInfoService bankcardInfoService;
	
	/**
	 * 订单评价
	 */
	@Resource(name = "evaluateService")
	private IEvaluateService evaluateService;
	
	/**
	 * 进入首页
	 * @return
	 */
	@RequestMapping("/toWxClientHome")
	public ModelAndView toWxClientHome(HttpServletRequest request,UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/home");
		
		String code = request.getParameter("code");
		System.out.println("home:code--------" + code);
		
		//获取公众号信息
		JSONObject jsonObject = WeiXinUtils.getUserInfo(code);
		
		//获取用户信息
		UserVo userVo = getOpenId(jsonObject);
		//UserVo userVo = userService.findByUsername(v);
		//获取分类
		WCategoryVo categoryVo = new WCategoryVo();
		List<WCategoryVo> listCategory = wCategoryService.findByWCategory(categoryVo);
		
		mv.addObject("listCategory",listCategory);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 个人中心
	 */
	@RequestMapping("/toMine.do")
	public ModelAndView toMine(HttpServletRequest request,UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/mine");
		
		String code = request.getParameter("code");
		System.out.println("home:code--------" + code);
		
		//获取公众号信息
		JSONObject jsonObject = WeiXinUtils.getUserInfo(code);
		
		//获取用户信息
		UserVo userVo = getOpenId(jsonObject);
		
		//UserVo userVo = userService.findByUsername(v);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	@RequestMapping("/toMineHome.do")
	public ModelAndView toMineHome(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/mine");
		UserVo userVo = userService.findByUsername(v);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 个人资料
	 * @param v
	 * @return
	 */
	@RequestMapping("/toAccountSetting.do")
	public ModelAndView toAccountSetting(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/accountSetting");
		UserVo userVo = userService.findByUsername(v);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 预约下单地址跳转
	 * @param v
	 * @return
	 */
	@RequestMapping("/toAccountSettingMine.do")
	public ModelAndView toAccountSettingMine(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/accountSettingMine");
		UserVo userVo = userService.findByUsername(v);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 详细地址
	 * @return
	 */
	@RequestMapping("/toAutoAddress.do")
	public ModelAndView toAutoAddress(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/autoAddress");
		mv.addObject("userId",v.getId());
		return mv;
	}
	
	/**
	 * 单独跳转到首页
	 * @param v
	 * @return
	 */
	@RequestMapping("/toHome")
	public ModelAndView toHome(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/home");
		UserVo userVo = userService.findByUsername(v);
		//获取分类
		WCategoryVo categoryVo = new WCategoryVo();
		List<WCategoryVo> listCategory = wCategoryService.findByWCategory(categoryVo);
		
		mv.addObject("listCategory",listCategory);
		mv.addObject("userVo",userVo);
		
		return mv;
	}
	
	/**
	 * 查看服务条款
	 */
	@RequestMapping("/toService")
	public ModelAndView toService(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/order/serviceAgreement");
		UserVo userVo = userService.findByUsername(v);
		//获取分类
		WCategoryVo categoryVo = new WCategoryVo();
		List<WCategoryVo> listCategory = wCategoryService.findByWCategory(categoryVo);
		
		mv.addObject("listCategory",listCategory);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 进入参考价
	 */
	@RequestMapping("/toReferencePrice")
	public ModelAndView toReferencePrice(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/order/referencePrice");
		//参考价模版
		WPricetemplateVo pricetemplateVo = wPricetemplateService.findByWPriceTemplate();
		
		mv.addObject("userVo",v);
		mv.addObject("pricetemplateVo",pricetemplateVo);
		return mv;
	}
	
	/**
	 * 进入下单页
	 */
	@RequestMapping("/toOrder")
	public ModelAndView toOrder(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/order/order");
		WCategoryVo categoryVo = new WCategoryVo();
		List<WCategoryVo> listCategory = wCategoryService.findByWCategory(categoryVo);
		UserVo userVo = userService.findByUsername(v);
		
		mv.addObject("userVo",userVo);
		mv.addObject("listCategory",listCategory);
		return mv;
	}
	
	/**
	 * 进入添加地址页
	 */
	@RequestMapping("/toAddress")
	public ModelAndView toAddress(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/order/add_address");
		UserVo userVo = userService.findByUsername(v);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 添加地址
	 * @param v
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/toSaveAddress.do")
	public AjaxResult<String> toSaveAddress(UserVo v){
		AjaxResult<String> ajaxResult = new AjaxResult<String>();
		UserVo userVo = userService.find(v.getId());
		//详细地址
		userVo.setAddress(v.getAddress());
		userVo.setContacts(v.getContacts());
		userVo.setTelephone(v.getTelephone());
		//收货地址 根据详细地址查询省
		JSONObject jsonObject = WebUtil.getAddress(v.getArea()+v.getAddress());
		System.out.println("地址------"+v.getArea()+v.getAddress());
		if (jsonObject != null) {
			userVo.setProvince(jsonObject.getString("province"));
			userVo.setCity(jsonObject.getString("city"));
			userVo.setArea(jsonObject.getString("district"));
			String[] location = jsonObject.getString("location").split(",");
			userVo.setLng(location[0]);
			userVo.setLat(location[1]);
			userService.updateUser(userVo);
			
			ajaxResult.setMsg("1");
		}else {
			ajaxResult.setMsg("2");
		}
		
		return ajaxResult;
	}
	
	/**
	 * 
	 * @param 下单成功
	 * @param categoryStr
	 * @param weightStr
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/toAdd.do")
	public AjaxResult<String> toAdd(WOrderVo v,
			@RequestParam(value = "categoryStr[]")String[] categoryStr,
			@RequestParam(value = "weightStr[]")String[] weightStr){
		AjaxResult<String> ajaxResult = new AjaxResult<String>();

		System.out.println("下单进入回收员id-------"+v.getReceiptId());
		//根据用户发单地区分配给相同地区商家
		UserVo user = userService.find(new BigInteger(v.getUserId()));
		if (user != null) {
			String weight = weightStr[0];
			System.out.println("-----------" + weight);
			if (weight.equals("20~50kg") || weight.equals("50~100kg")) {
				user.setWxType(3);
			}else if (weight.equals("100~200kg") || weight.equals("200kg以上")) {
				user.setWxType(4);
			}
			
			if (user.getLat() != null) {
				//优先司机接单
				System.out.println("进入用户下单方法-----------"+JSON.toJSONString(user));
				List<UserVo> userVos = userService.findByUserLatLng(user);
				if (userVos.size()>0 ) {
					//接单人
					v.setReceiptId(userVos.get(0).getId().toString());
				}else {
					//如没有司机，派单给回收员
					user.setWxType(3);
					List<UserVo> userVo = userService.findByUserLatLng(user);
					if (userVo.size()>0 ) {
						//接单人
						v.setReceiptId(userVo.get(0).getId().toString());
					}else {
						v.setReceiptId("");
					}
				}
			}
		}
		
		//设置订单编号
		v.setOrderNumber(RandomUtils.random6());
				
		v.setProvince(user.getProvince());
		v.setCity(user.getCity());
		v.setArea(user.getArea());
		v.setAddress(user.getAddress());
		v.setType(1);
		
		//判断当前区域是否有商家
		if (v.getReceiptId() != "" && v.getReceiptId() != null) {
			//进行中
			v.setStatus(1);
			
			//发送消息模版使用的分类属性
			String category = "";
			if (categoryStr != null) {
				
				/*WOrderCategoryVo orderCategoryVo = new WOrderCategoryVo();
				//分类
				orderCategoryVo.setwCategoryId(String.join(",", categoryStr));
				//重量范围
				orderCategoryVo.setWeight(String.join(",", weightStr));
				//订单编号
				orderCategoryVo.setOrderNumber(v.getOrderNumber());
				
				wOrderCategoryService.save(orderCategoryVo);
				
				//查询选择的分类
				List<WCategoryVo> categoryVos = wCategoryService.findByWCategoryMap(categoryStr);
				if (categoryVos.size()>0) {
					for (WCategoryVo c : categoryVos) {
						category += c.getName() +"\r\n" ;
					}
				}*/
				
				for (int i = 0 ;i<categoryStr.length; i++) {
					WOrderCategoryVo orderCategoryVo = new WOrderCategoryVo();
					orderCategoryVo.setwCategoryId(categoryStr[i]);
					orderCategoryVo.setWeight(weightStr[0]);
					//订单编号
					orderCategoryVo.setOrderNumber(v.getOrderNumber());
					
					WCategoryVo categoryVo = new WCategoryVo();
					categoryVo.setCategoryId(categoryStr[i]);
					List<WCategoryVo> categoryVos = wCategoryService.findByWCategory(categoryVo);
					//category += categoryVos.get(0).getName() +":"+weightStr[0] +"\r\n" ;
					category += categoryVos.get(0).getName() +"\r\n" ;
					wOrderCategoryService.save(orderCategoryVo);
				}
			}
			//重量范围
			category += "货量范围:"+weightStr[0];
			//获取微信token
			WeixinVo weixinVo = weixinService.findByWeixin();
			//查询回收员名称和电话
			UserVo vo = userService.find(new BigInteger(v.getReceiptId()));
			//发送消息模版
			Map<String,TemplateData> param = new HashMap<>();
	        param.put("first",new TemplateData("订单已受理","#696969"));
	        param.put("OrderSn",new TemplateData(v.getOrderNumber(),"#696969"));
	        param.put("OrderStatus",new TemplateData("已受理","#696969"));
			param.put("remark",new TemplateData("预约时间："+v.getPickTime()+" \r\n"
		        		+ "回收员："+vo.getContacts()+" \r\n"
		        		+ "回收员电话："+vo.getTelephone()+" \r\n"
		        		+category
		        		+ "请提前与回收员联系 \r\n","#696969"));
			
	        //调用发送微信消息给用户的接口
	        WeiXinUtils.sendWechatMsgToUser(weixinVo.getAccessToken(),user.getWxOpenId(),Constants.TEMPLATE, "", "#000000", WeiXinUtils.packJsonmsg(param));
	        
	       /* //发送消息模版
	  		Map<String,TemplateData> par = new HashMap<>();
	  		par.put("first",new TemplateData("接单啦","#696969"));
	  		par.put("tradeDateTime",new TemplateData(v.getCreateTime(),"#696969"));
	  		par.put("orderType",new TemplateData("进行中","#696969"));
	  		par.put("customerInfo",new TemplateData(user.getContacts(),"#696969"));
	  		par.put("orderItemName",new TemplateData("联系电话","#696969"));
	  		par.put("orderItemData",new TemplateData(user.getTelephone(),"#696969"));
	  		par.put("remark",new TemplateData(category 
	  				+"预约时间："+v.getPickTime()+" \r\n"
	  				+ "请提前与用户联系 \r\n","#696969"));
	  		//调用发送微信消息给回收员的接口
	        WeiXinUtils.sendWechatMsgToReceipt(weixinVo.getAccessToken(),vo.getWxOpenId(),Constants.RECEIPT, "", "#000000", WeiXinUtils.packJsonmsg(par));*/
		}else {
			//无人接单
			v.setStatus(4);
		}
		
		wOrderService.save(v);
		ajaxResult.setMsg("1");
		
		return ajaxResult;
	}
	
	/**
	 * 查询当前用户所有订单
	 * @param request
	 * @param id
	 * @param status
	 * @return
	 */
	@RequestMapping("/toOrderList")
	public ModelAndView toOrderList(HttpServletRequest request,String id,Integer status) {
		ModelAndView mv = new ModelAndView("/wx/client/order/order_list");
		 UserVo userVo = new UserVo();
		if (id != null) {
			userVo.setId(new BigInteger(id));
			userVo = userService.findByUsername(userVo);
		}else {
			String code = request.getParameter("code");
			System.out.println("order:code--------" + code);
			//获取公众号信息
			JSONObject jsonObject = WeiXinUtils.getUserInfo(code);
			//获取用户信息
			userVo = getOpenId(jsonObject);
		}
		
		mv.addObject("userVo",userVo);
		
		return mv;
	}
	
	/**
	 * 修改订单状态
	 * @param v
	 * @return
	 * @throws IOException
	 */
	@ResponseBody
	@RequestMapping("/updateOrder")
    public  AjaxResult<String> updateOrder(WOrderVo v) throws IOException {
		AjaxResult<String> ajaxResult = new AjaxResult<String>();
		WOrderVo orderVo = wOrderService.find(new BigInteger(v.getbId()));
		orderVo.setStatus(v.getStatus());
		String flag = wOrderService.updateStatus(orderVo);
		ajaxResult.setMsg(flag);
		return ajaxResult;
	}
	
	/**
	 * 验证openid 是否存在，不存在新增
	 * @param jsonObject
	 * @return
	 */
	public UserVo getOpenId(JSONObject jsonObject) {
		//获取openid
		String openId = jsonObject.getString("openid");
		//昵称
		String nickName = jsonObject.getString("nickName");
		//头像
		String avatarUrl = jsonObject.getString("avatarUrl");
		
		System.out.println("openid-------" + openId);
		UserVo user = new UserVo();
		user.setWxOpenId(openId);
		user = userService.findByUserOpenid(user);
		if (user == null ) {
			user = new UserVo();
			user.setWxOpenId(openId);
			user.setWxType(1);
			user.setStatus(1);
			user.setUserImg(avatarUrl);
			user.setNickName(nickName);
			user.setAuditStatus(1);
			userService.save(user);
			
			//创建个人账户
			AccountVo account = new AccountVo();
			account.setUserId(user.getId().toString());
			account.setAmount(0f);
			accountService.save(account);
		}
		return user;
	}
	
	/**
	 * 我的账户余额
	 */
	@RequestMapping("/toMyAccount")
	public ModelAndView toMyAccount(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/myBalance");
		AccountVo accountVo = accountService.findByUserId(userId);
		mv.addObject("accountVo",accountVo);
		return mv;
	}
	
	/**
	 * 余额提现
	 */
	@RequestMapping("/toGetCash")
	public ModelAndView toGetCash(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/getCash");
		UserVo v = new UserVo();
		v.setId(new BigInteger(userId));
		UserVo userVo = userService.findByUsername(v);
		
		AccountVo accountVo = accountService.findByUserId(userId);
		
		//用户银行卡信息
		BankcardInfoVo bankcardInfoVo = new BankcardInfoVo();
		bankcardInfoVo.setUserId(userId);
		BankcardInfoVo bankcardInfo = bankcardInfoService.findByBankcardInfo(bankcardInfoVo);
		if (bankcardInfo != null) {
			int length = bankcardInfo.getBankCardNumber().length();
			bankcardInfo.setBankCardNumber(bankcardInfo.getBankCardNumber().substring(0,4)+"********"+bankcardInfo.getBankCardNumber().substring(length-4));
			bankcardInfo.setBankName(bankcardInfo.getBankName().substring(0,0)+"*"+bankcardInfo.getBankName().substring(1));
			mv.addObject("bankcardInfoVo", bankcardInfo);
		}else {
			 mv = new ModelAndView("/wx/client/mine/bindBankCard");
		}
		mv.addObject("accountVo",accountVo);
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 我的银行卡
	 */
	@RequestMapping("/toMyBank")
	public ModelAndView toMyBank(String id) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/myBankCard");

		//用户银行卡信息
		BankcardInfoVo bankcardInfoVo = new BankcardInfoVo();
		bankcardInfoVo.setUserId(id);
		BankcardInfoVo bankcardInfo = bankcardInfoService.findByBankcardInfo(bankcardInfoVo);
		if (bankcardInfo != null) {
			int length = bankcardInfo.getBankCardNumber().length();
			bankcardInfo.setBankCardNumber(bankcardInfo.getBankCardNumber().substring(0,4)+"********"+bankcardInfo.getBankCardNumber().substring(length-4));
			bankcardInfo.setBankName(bankcardInfo.getBankName().substring(0,0)+"*"+bankcardInfo.getBankName().substring(1));
			mv.addObject("bankcardInfoVo", bankcardInfo);
		}else {
			mv.addObject("bankcardInfoVo",bankcardInfo);
		}
		mv.addObject("userId",id);
		return mv;
	}
	
	/**
	 * 我的二维码
	 */
	@RequestMapping("/toMyCode")
	public ModelAndView toMyCode(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/myCode");
		UserVo userVo = userService.findByUserId(new BigInteger(userId));
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 意见反馈页面
	 */
	@RequestMapping("/toSuggestion")
	public ModelAndView toSuggestion(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/suggestion");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 用户对账单页面
	 */
	@RequestMapping("/toStatement")
	public ModelAndView toStatement(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/statement");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 用户明细
	 */
	@RequestMapping("/toBalanceDetail")
	public ModelAndView toBalanceDetail(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/balanceDetail");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 安全设置
	 */
	@RequestMapping("/toSecurity")
	public ModelAndView toSecurity(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/security");
		
		UserVo userVo = userService.findByUsername(v);
		//查询是否设置支付密码 1 设置 2未设置
		PayPassVo passVo = payPassService.findByPayUserId(userVo.getbId());
		if (passVo != null) {
			userVo.setPayStatus(1);
		}else {
			userVo.setPayStatus(2);
		}
		
		//用户银行卡信息
		BankcardInfoVo bankcardInfoVo = new BankcardInfoVo();
		bankcardInfoVo.setUserId(userVo.getbId());
		BankcardInfoVo bankcardInfo = bankcardInfoService.findByBankcardInfo(bankcardInfoVo);
		if (bankcardInfo != null) {
			mv.addObject("bankcardInfoVo", bankcardInfo);
		}else {
			mv.addObject("bankcardInfoVo",bankcardInfo);
		}
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 设置支付密码页面
	 */
	@RequestMapping("/toSetPassword")
	public ModelAndView toSetPassword(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/setPassword");
		
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 修改支付密码页面
	 */
	@RequestMapping("/toMdifySetPassword")
	public ModelAndView toMdifySetPassword(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/modifySetPassword");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 忘记支付密码页面
	 */
	@RequestMapping("/toMdifyPassword")
	public ModelAndView toMdifyPassword(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/modifyPassword");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 身份认证
	 */
	@RequestMapping("/toCheckSetPassword")
	public ModelAndView toCheckSetPassword(String userId) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/checkSetPassword");
		mv.addObject("userId",userId);
		return mv;
	}
	
	/**
	 * 绑定银行卡认证
	 */
	@RequestMapping("/toBindBankCard")
	public ModelAndView toBindBankCard(UserVo v) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/bindBankCard");
		
		UserVo userVo = userService.findByUsername(v);
		//查询是否设置支付密码 1 设置 2未设置
		PayPassVo passVo = payPassService.findByPayUserId(userVo.getbId());
		if (passVo != null) {
			userVo.setPayStatus(1);
		}else {
			userVo.setPayStatus(2);
		}
		
		//用户银行卡信息
		BankcardInfoVo bankcardInfoVo = new BankcardInfoVo();
		bankcardInfoVo.setUserId(userVo.getbId());
		BankcardInfoVo bankcardInfo = bankcardInfoService.findByBankcardInfo(bankcardInfoVo);
		if (bankcardInfo != null) {
			mv.addObject("bankcardInfoVo", bankcardInfo);
		}else {
			mv.addObject("bankcardInfoVo",bankcardInfo);
		}
		
		mv.addObject("userVo",userVo);
		return mv;
	}
	
	/**
	 * 身份认证
	 */
	@RequestMapping("/toQuestion")
	public ModelAndView toQuestion() {
		ModelAndView mv = new ModelAndView("/wx/client/mine/question");
		return mv;
	}
	
	/**
	 * 用户明细
	 */
	@RequestMapping("/toGetCashProgress")
	public ModelAndView toGetCashProgress(String userId,String createTime,String bankCardName,String bankCardNumber,String price) {
		ModelAndView mv = new ModelAndView("/wx/client/mine/getCashProgress");
		bankCardNumber = (bankCardNumber.substring(0,4)+"********"+bankCardNumber.substring(bankCardNumber.length()-4));
		createTime = createTime.substring(10, 15);
		mv.addObject("userId",userId);
		mv.addObject("createTime",createTime);
		mv.addObject("bankCardName",bankCardName);
		mv.addObject("bankCardNumber",bankCardNumber);
		mv.addObject("price",price);
		return mv;
	}
	
	
	/**
	 * 查询订单是否有评价
	 */
	@RequestMapping("/toEvaluate")
	public ModelAndView toEvaluate(EvaluateVo v,String orderNum) {
		ModelAndView mv = new ModelAndView("");
		List<EvaluateVo> list = evaluateService.findByEvaluate(v);
		if (list.size()>0) {
			mv = new ModelAndView("/wx/client/order/evaluate_detail");
			mv.addObject("list",list.get(0));
		}else {
			mv = new ModelAndView("/wx/client/order/evaluate");
			mv.addObject("evaluateVo",v);
		}
		
		return mv;
	}
	
}
